/*******************************************************************************
 * TemplateSettingDelegator.java
 *
 * Created by Ankur
 * Last modified Date: Sep 9, 2008 2:25:46 PM by Ankur
  * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ******************************************************************************/

package com.printeverywhere.delegator;

import java.util.List;
import static com.printeverywhere.util.AttributeConstants.*;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.printeverywhere.dto.Template;
import com.printeverywhere.util.HibernateUtil;

/**
 * The Class TemplateSettingDelegator.
 */
public class TemplateSettingDelegator {
	
	/** The log. */
	private static Logger log = Logger.getLogger(TemplateSettingDelegator.class);
	
	/**
	 * Gets the template list.
	 * 
	 * @return the template list
	 * 
	 * @throws HibernateException the hibernate exception
	 */
	@SuppressWarnings("unchecked")
	public static List<Template> getTemplateList() throws HibernateException {
		if(log.isInfoEnabled()){
			log.info("Getting list for Template ".intern());
		}
		Session session = HibernateUtil.getSession();
		try {
			Transaction transaction = session.beginTransaction();
			List<Template> list = session.createCriteria(Template.class).list();
			transaction.commit();
			return list;
		} catch (HibernateException e) {
			log.error("Got exception when getting list for Template ".intern());
			throw e;
		} finally {
			if(log.isInfoEnabled()){
				log.info(CLOSING_SESSION);
			}
			session.flush();
			session.close();
		}
	}
}